/* eslint-disable max-classes-per-file */
/* eslint-disable no-console */
export interface IData {
	key: number
}

export class DataClass implements IData {
	constructor(public key: number, public data: number) { }
}

export class DirectAddress<T extends IData> {
	data: T[] = []

	search(k: number): T {
		return this.data[k]
	}

	insert(x: T) {
		this.data[x.key] = x
	}

	delete(x: T) {
		delete this.data[x.key]
	}
}

const s = new DirectAddress<DataClass>()

s.insert(new DataClass(3, 30))
s.insert(new DataClass(2, 20))
s.insert(new DataClass(1, 10))
console.log(s.data)
s.delete(s.search(2)!)
console.log(s.data)
